﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


namespace Unity.Game.ElisAdvance.ElisScript
{
    //玩家elis引入事件
    public class ElisState_Dash
    {
        public static void onProc(ElisActiveObject activeObject)
        {

            float subState = activeObject.getStateVector(0);

            if (subState == 0)
            {
                if (activeObject.getStateTimer() > 0.1f)
                {

                    activeObject.clearStateVector();
                    activeObject.pushStateVector(1);
                    activeObject.setState(State.STATE_DASH);
                }

            }
            else if (subState == 1)
            {
                if (activeObject.getStateTimer() > 0.3f)
                {

                    activeObject.clearStateVector();
                    activeObject.pushStateVector(2);
                    activeObject.setState(State.STATE_DASH);
                }

            }
            else if (subState == 2)
            {
                if (activeObject.getStateTimer() > 0.1f)
                {
                    if (activeObject.isLand())
                    {
                        activeObject.clearStateVector();
                        activeObject.pushStateVector(1);
                        activeObject.setState(State.STATE_STAND);
                    }
                    else
                    {
                        activeObject.clearStateVector();
                        activeObject.pushStateVector(1);
                        activeObject.setState(State.STATE_JUMP);
                    }

   
                }


            }

        }

        public static void onEndState(ElisActiveObject obj, State state)
        { 
            if (state != State.STATE_DASH)
            {
                obj.getAniManager().setAni("DashType", 0);
                obj.setXVelocity(0);
            }
        
        }

        public static void onSetState(ElisActiveObject activeObject)
        {
            activeObject.getGravityEvent().setEnable(false);
            float subState = activeObject.getStateVector(0);
            if (subState == 0)
            {
                activeObject.getVar("GLOBAL_horiztantlKey").clear_vector();
                activeObject.getAniManager().setAni("DashType",1);
                activeObject.sendInvincibleTime(0.5f);
                activeObject.setXVelocity(Dir.getDirectionVar(activeObject.getDirection(), activeObject.getMoveSpeedX()));
                activeObject.getGravityEvent().setEnable(false);
            }
            else if (subState == 1)
            {

                activeObject.getVar("GLOBAL_horiztantlKey").clear_vector();
                activeObject.getAniManager().setAni("DashType",2);
                activeObject.setXVelocity(Dir.getDirectionVar(activeObject.getDirection(), activeObject.getMoveSpeedX() * 2.0f));
                activeObject.setYVelocity(0.0f);
                activeObject.getGravityEvent().setEnable(false);

            }
            else if (subState == 2)
            {
                activeObject.getVar("GLOBAL_horiztantlKey").clear_vector();
                activeObject.getAniManager().setAni("DashType",1);
                activeObject.setXVelocity(Dir.getDirectionVar(activeObject.getDirection(), activeObject.getMoveSpeedX()));
                activeObject.getGravityEvent().setEnable(false);

            }

        }
    }
}